package com.example.mlm;


import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;

public class MyPlayer extends Service {
	private MediaPlayer mp;
	
	@Override
	public void onCreate() {
	}
	
	@Override
	public void onDestroy() {
		mp.stop();
		super.onDestroy();
	}
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		String musique = intent.getExtras().getString("musique");
				
		if(mp!=null && mp.isPlaying())
			return super.onStartCommand(intent, flags, startId);
			
		mp = new MediaPlayer();
		try{
			mp.setDataSource(musique);
			mp.prepare(); 
		}catch(Exception e){
			e.printStackTrace();
		}
		
		mp.start();
		mp.setLooping(false);
		return super.onStartCommand(intent, flags, startId);
	}
	
	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

}
